import { _decorator, Component, input, Input, Animation, JsonAsset, director, EventKeyboard, KeyCode, game, AudioSource, Label, EventMouse, Graphics, Color, Node, UITransform, Vec3, Sprite, AnimationClip} from "cc";
import { defined } from "../hyxh/core/Defined";
import { Cartesian3 } from "../hyxh/core/Cartesian3";
import { HNetsPolyline } from "../hyxh/core/HYXHNetsPolyline";
import { ICartesian } from "../hyxh/core/Cartesian";
import { Check } from "../hyxh/core/Check";
import { Cion } from "./cion";
import { SpritePlayer } from './SpritePlayer';
import { BelialHunter } from './BelialHunter';
import { Queue } from '../hyxh/core/Queue';
import { SecenesManager } from './SecenesManager';
import { HAnimationFrame, HAnimationResource, HAudioResource, HImageResource } from './HResource';
import { ElevatorController } from './ElevatorController';
import { StageController } from './StageController';
const { ccclass, property } = _decorator;

export const BLOCK_SIZE = 40;
export const BLOCK_CION_SIZE = 12;

export enum GAME_STATE {
    UNKNOWN = 0,   /* 未知 */
    IDLE = 1,      /* 空闲 */
    RUN = 2,       /* 运行 */
    LOST = 3,      /* 丢失，被捕捉 */
    FAILURE = 4   /* 失败 */
}

@ccclass('SeceneInitializer')
export class SecenseTools extends Component {
    /* 当前Secen对应配置文件 */
    public jsonConfig:object = null;

    @property(Animation)
    BodyAnim:Animation = null;

    @property(JsonAsset)
    itemGiftJson: JsonAsset = null!;

    /* 游戏默认状态 */
    gamestate: GAME_STATE = GAME_STATE.RUN;

    /* 金币的超时时间 */
    public static MAX_IDLE_TIME_CION: number = 0;

    @property('network')
    public _network: HNetsPolyline = null;

    /* 金币 */
    public CION_LIST = new Array<Cion>();  
    /* 播放动画用Sprite */
    private animationNode : Node = null;
    private animationSprite:Sprite = null;

    /**
     * 精灵（在迷宫）
     */
    public spritePlayer: SpritePlayer = null;
    /**
     * 进入迷宫的精灵的初始位置,
     * 该位置，在hxpath.json中配置
     */
    private spriterStartPosition : Cion = null;

    /**
     * 追捕猎人， JSON配置了多少，就应用多少
     */
    public BELIALS_BUFFER: Array<BelialHunter> =[];
    /**
     * 背景音乐
     */
    public audio_background_id: number = -1;    

    /* 门对记录, 传送门 */
    stage_team_map : Map<number, Array<StageController>> = new Map();
    
    /* 电梯，及其运行路径 */
    elevators : Array<ElevatorController> = [];
    /* 管理, 精灵等待列表，用于支持重新开始 */
    _SPRITED_TAKEED_BUFFER: SpritePlayer[] = [];
    /* 等待列表，用于排列在顶部 */
    _SPRITED_IDLE_BUFFER: SpritePlayer[] = [];
    
    _bk_audio_rid : number =9001010;
    /* 初始化 */
    _sprite_lose_audio: number  = 9001011;          //"lose":9001011,
    _sprite_failure_audio: number = 9001012;        // "failure":9001012,
    _sprite_victory_audio: number = 9001012;        // "victory":9001013,
    _sprite_walkanim_anima: number =  80110001;     // "walkanim":80110001,
    _sprite_takedanim_anima: number = 80110004;     // "takedanim":80110004,
    _sprite_failureanim_anima: number = 80110002;   // "failureanim":80110002,
    _sprite_victoryanim_anima: number = 80110003;   // "victoryanim":80110003,

    public gamePause() {
        this.gamestate = GAME_STATE.IDLE;
    }
    public gameRun() {
        this.gamestate = GAME_STATE.RUN;
    }
    public isGameRun(): boolean {
        return this.gamestate == GAME_STATE.RUN;
    }

    public getNetWork() : HNetsPolyline {
        return this._network;
    }

    start() {
        /* 加载JSON 资源 */
        this.loadjsonConfig();
        /* 初始化cion */
        input.on(Input.EventType.KEY_PRESSING, this.onEventKeyboard, this);    
        input.on(Input.EventType.KEY_DOWN, this.onEventKeyDown, this);    
        input.on(Input.EventType.KEY_UP, this.onEventKeyUP, this);    

        input.on(Input.EventType.MOUSE_DOWN,this.onMouseDown, this ); 

        game.canvas.focus();        
    }

    _is_line_end : boolean = false;
    _coords : Array<number> = [];
    _cur_index : number = 0;
    onMouseDown(event: EventMouse){
        const location = event.getLocation();
        
        const _graphic_child_node = this.node.getChildByName('graphics');
        let postion_tmp_v3 = _graphic_child_node.getComponent(UITransform).convertToNodeSpaceAR(new Vec3(location.x, location.y, 0.0));

        this._coords.push(postion_tmp_v3.x);
        this._coords.push(postion_tmp_v3.y);
        if (this._is_line_end) {
            this.drawLine(this._cur_index, this._coords);            
            this._cur_index++;

            this._coords = [];
        }
        this._is_line_end = !this._is_line_end;
    } 
    drawLine(index:number,  linecoords: Array<number>) {
        
        const child_node = this.node.getChildByName('graphics');
        const _grahics = child_node.getComponent(Graphics);

        _grahics.lineWidth = 2;
        _grahics.lineCap = Graphics.LineCap.SQUARE;
        _grahics.strokeColor = Color.WHITE;
        _grahics.moveTo(linecoords[0], linecoords[1]);
        _grahics.lineTo(linecoords[2], linecoords[3]);
        _grahics.stroke();
        
        console.log( index.toString() + ":" + "[" +  linecoords[0] + ", "
                                                  +  linecoords[1] + ", "
                                                  +  "0.00, "
                                                  +  linecoords[2] + ", "
                                                  +  linecoords[3] + ", "
                                                  +  "0.00 "
                                                  +  "] "
                                                );
    }

    public showLabel(_string: string) {
        if (!defined(_string)) {
            return;
        }
        const child_node = this.node.getChildByName('lbjifen');
        if (!defined(child_node)) {
            return;
        }
        const label_for_Show = child_node.getComponent(Label);
        if (defined(label_for_Show)) {
            label_for_Show.string = _string;
        } 
    }
    
    /* 鼠标操作 */
    onEventKeyboard(event:EventKeyboard) {
        if (!defined(this.spritePlayer)) {
            return;
        }
        this.spritePlayer.movenext(event.keyCode);
    }
    onEventKeyDown(event: EventKeyboard) {
        if (!defined(this.spritePlayer)) {
            return;
        }
        this.spritePlayer.spriterun();
        this.spritePlayer.movenext(event.keyCode);
    }

    onEventKeyUP(event:EventKeyboard) {
        if (!defined(this.spritePlayer)) {
            return;
        }
        /* 精灵停止，如果在一个步骤内，有大于1的路口，则默认停在三叉路口 */
        this.spritePlayer.spritestop();        
    }

    /**
     * 判断是否在一个交叉路口（三叉或者十字）
     * @param _cnode 
     * @returns 
     */
    public locationCrossPoint(_cnode: Cion): Cion | null {
       if (!defined(_cnode)) {
            return null;
        }
        const _layer_id = _cnode.points[0];
        const _point_index = _cnode.points[1];
        const _point_is = this._network.indexNearLines(_layer_id, _point_index);
        if (!defined(_point_is)) {
            return null;
        }
        /* 利用递归进行处理 */
        const _cions = this.findNextPositionList(_cnode);
        if (!defined(_cions)) {
            return _cnode;
        }
        if (_cions.length > 2) {
            return _cnode;
        }
        const _queue = new Queue<Cion>();
        for (let _cion of _cions) {
            if (!defined(_cion)) {
                continue;
            }
            _queue.enqueue(_cion); 
        }
        while(!_queue.isEmpty()) {
            const _cion = _queue.dequeue();
            if (!defined(_cion)) {
                continue;
            }
            const _next_cions = this.findNextPositionList(_cion);
            if (!defined(_next_cions)) {
                continue; 
            }
            if (_next_cions.length > 2) {
                return _cion; 
            }
        }
        return _cnode;        
    }

    public isCrossPoint(_cnode: Cion): boolean {
        if (!defined(_cnode)) {
            return false;
        }
        const _next_cions = this.findNextPositionList(_cnode);
        if (!defined(_next_cions)) {
            return false;
        }
        return _next_cions.length > 2;
    }

    /**
     * 根据坐标是否进入一个电梯
     * @param _cnode 
     */
    public isTouchElevator(_cnode: Cion): boolean {
        /* 判断下一个节点, 当前位置，存在下一个cion 是Evelator */
        const next_cion = this.findNextPositionForElevator(_cnode);
        if (defined(next_cion)) {
            return true;
        }
        return false;
    }

    public findNearestPoint(point: ICartesian): Cion | null {
        Check.defined("point", point);
        Check.typeOf.object("point", point);
        
        if (!defined(this._network)) {
            return null;
        } 
        let minDistance = Number.MAX_VALUE;
        let sel_cion : Cion | null = null;
        for(let cion_pos of this.CION_LIST) {
            if (!defined(cion_pos)) {
                continue;           
            } 
            if (!defined(cion_pos.position)) {
                continue; 
            }
            const _layer_id = cion_pos.points[0];
            if (!defined(_layer_id)) {
                continue;
            }
            const _point_index = cion_pos.points[1];
            if (!defined(_point_index)) {
                continue;
            }
            const _point = this._network.indexPoints(_layer_id, _point_index);
            if (!defined(_point)) {
                continue; 
            }

            const cdistance = Cartesian3.distance(point, _point);
            if ( minDistance > cdistance) {
                minDistance = cdistance; 
                sel_cion = cion_pos;
            }
        }
        return sel_cion;
    }
    /**
     * 在当前位置，周围有电梯轨道
     * 判断是否有电梯，根据电梯轨道，找到对应Elvator Controller , 
     * 启动移动
     * @param _cnode 
     * @param keycode 
     */
    public findNextPositionForElevator(_cnode: Cion): ElevatorController | null {
        Check.defined("_cnode", _cnode);
        Check.typeOf.object("_cnode", _cnode);
        /* 获得当前点的位置 */
        for( let elevator of this.elevators) {
            if (!defined(elevator)) {
                continue;
            }
            if (elevator.isTouched(_cnode)){
                return elevator;            } 
        }
        return null;
    }

    /**
     * 开始电梯移动
     * @param _cnode 
     * @returns 
     */
    public startElevatorMove(elevator: ElevatorController, targ_node_pos: Cion) {
        /* 启动移动 */
        if (!defined(elevator)) {
            return; 
        }
        /* 根据当前cion 进行电梯路径查询， 并确定电梯精灵的位置 */
        if (!defined(targ_node_pos)) {
            return; 
        }

        /* 根据_cnode 找到对应的电梯  */
        if (!targ_node_pos.getElevatorSign()) {
            return; 
        }

        if (elevator.getNodePos() == targ_node_pos ){
            return;
        }
        if (elevator.getNodePos().equalsPosition(targ_node_pos)){
            return;
        }
        elevator.activity = true;

    }

    /**
     * 找到合理电梯精灵
     * @param cnodePost 
     * @returns 
     */
    public findElevator(cnodePost: Cion) : ElevatorController | undefined {
        if (!defined(cnodePost)) {
            return undefined;
        }
        if (!defined(this.elevators)) {
            return undefined;
        }

        for(let elevatorController of this.elevators) {
            if (!defined(elevatorController)) {
                continue;
            }
            const path_index = elevatorController.getPath();
            if (cnodePost.hasSamePath(path_index) ) {
                return elevatorController;
            }   
        }
        return undefined;
    }
    /**
     * 检索 _cnode 周边的位置
     * @param _cnode 
     */
    public findNextPositionList(_cnode: Cion): Array<Cion> | null {
        Check.defined("_cnode", _cnode);
        Check.typeOf.object("_cnode", _cnode);
        /* 获得当前点的位置 */
        const _layer_id = _cnode.points[0];
        const _point_index = _cnode.points[1];
        const _point_is = this._network.indexNearLines(_layer_id, _point_index);
        if (!defined(_point_is)) {
            return null; 
        }
        if ( _point_is.length < 2) {
            return null;
        }
        let query_result= new Array<Cion>();
        let index_cursor = 0; 
        while(index_cursor < _point_is.length) {
            const _cursor_layer_id = _point_is[index_cursor + 2];
            const _cursor_point_index = _point_is[index_cursor+ 3];
            index_cursor += 4;
            const _point = this._network.indexPoints(_cursor_layer_id, _cursor_point_index);
            if (!defined(_point)) {
                continue;
            }
            const _cion_post = this._network.indexPoints( _cnode.points[0], _cnode.points[1] );
            if (!defined(_cion_post)) {
                continue;
            }
            if ( Cartesian3.distance(_cion_post, _point) < BLOCK_CION_SIZE ) {
                continue;
            }
            const _point_cursor = this._network.indexPoints(_cursor_layer_id, _cursor_point_index);
            if (!defined(_point_cursor)) {
                continue;
            }
            const _cion_cursor = this.indexCion(_cursor_layer_id, _cursor_point_index);
            if (!defined(_cion_cursor)) {
                continue;
            }
            query_result.push(_cion_cursor);
        }
        return query_result;
    }

    /**
     * 发现在指定点的下一个位置
     * @param _cnode 
     */
    public findNextPosition(_cnode: Cion, keycode: number): Cion | null {
        Check.defined("_cnode", _cnode);
        Check.typeOf.object("_cnode", _cnode);
        Check.defined("keycode", keycode);
        Check.typeOf.number("keycode", keycode);
        /* 获得当前点的位置 */
        const _layer_id = _cnode.points[0];
        const _point_index = _cnode.points[1];
        const _point_is = this._network.indexNearLines(_layer_id, _point_index);
        if (!defined(_point_is)) {
            return null; 
        }
        if ( _point_is.length < 2) {
            return null;
        }
        let index_cursor = 0;
        let _select_layer_id = -1;
        let _select_point_index = -1;
        while(index_cursor < _point_is.length) {
            const _cursor_layer_id = _point_is[index_cursor + 2];
            const _cursor_point_index = _point_is[index_cursor+ 3];
            index_cursor += 4;
            const _point = this._network.indexPoints(_cursor_layer_id, _cursor_point_index);
            if (!defined(_point)) {
                continue;
            }
            const _cion_post = this._network.indexPoints( _cnode.points[0], _cnode.points[1] );
            if (!defined(_cion_post)) {
                continue;
            }
            if ( Cartesian3.distance(_cion_post, _point) < BLOCK_CION_SIZE ) {
                continue;
            }
            const _point_cursor = this._network.indexPoints(_cursor_layer_id, _cursor_point_index);
            if (!defined(_point_cursor)) {
                continue;
            }
            switch(keycode) {
                case KeyCode.ARROW_DOWN:
                    if ( _point_cursor.y < _cion_post.y ) {
                        _select_layer_id = _cursor_layer_id;
                        _select_point_index = _cursor_point_index;
                       break;
                    };
                    continue;
                case KeyCode.ARROW_UP:
                    if ( _point_cursor.y > _cion_post.y ) {
                        _select_layer_id = _cursor_layer_id;
                        _select_point_index = _cursor_point_index;
                        break;
                     };
                     continue;
                case KeyCode.ARROW_LEFT:
                    if ( _point_cursor.x < _cion_post.x ) {
                        _select_layer_id = _cursor_layer_id;
                        _select_point_index = _cursor_point_index;
                        break;
                    };
                    continue;
                case KeyCode.ARROW_RIGHT:
                    if ( _point_cursor.x > _cion_post.x ) {
                        _select_layer_id = _cursor_layer_id;
                        _select_point_index = _cursor_point_index;
                        break;
                    };
                    continue;
                default:
                    continue;                
            }
        }
        let new_node = this.indexCion(_select_layer_id, _select_point_index);
        if (!defined(new_node)) {
            new_node = _cnode;
        }
        return new_node;
    }

    public indexCion(_layer_id: number, _point_index: number): Cion | null {
        
        const path_len = this._network.getPathSize(_layer_id);
        if (path_len <= 0) {
            return null;
        }
        if (_point_index >= path_len) {
            return null; 
        } 
        if (!defined(this.CION_LIST)) {
            return null; 
        }
        let _index = _point_index;
        if (_index < 0) {
            _index = path_len + _index;
        }
        
        for(let cion_pos of this.CION_LIST) {
            if (!defined(cion_pos)) {
                continue;
            }
            if (cion_pos.hasSamePosition(_layer_id, _index)) {
                return cion_pos;
            }
        } 
        return null;
    }

    loadScene() {
        // 加载场景，这里以 "MainScene" 为例
        director.loadScene('gamehome', null, () => {
           
            console.log('Scene loaded======');
             /* 加载JSON 资源 */
            this.loadjsonConfig();
            console.log('Scene 加载成功！');
        });
    }
    /**
     * 根据json 配置文件加载Secene, 并实例化精灵和Hunter
     * @returns 
     */
    loadjsonConfig() {
        const secenes_ref = SecenesManager.getInstance();
        if (!defined(secenes_ref)) {
            return;
        }
        
        const secene_ref = secenes_ref.getSeceneReference('gamehome');
        if (!defined(secene_ref)) {
            return; 
        }
        /* 根据配置初始化 */
        this.jsonConfig = secene_ref; 
        /* 加载金币链条 */
        this.loadIconsComponent();
        /* 初始化音频 */
        this.initAudio();   
        this.initAnimation();     
        /* 初始化猎手 */
        this.initializeHunter();
        /* 初始化电梯 */
        this.initializeElevators();
        /* 初始化传送门 */
        this.initializeStages();
        /* 初始化入口 */
        this.initSpriteStartPosition();
        /* 初始化精灵、猎手、 */
        this.initializeSprites();
        /* 初始化动画节点 */
        this.initAnimatioNode();
    }

    private initSpriteStartPosition() {
        if (!defined(this.jsonConfig)) {
            throw new Error("this.jsonConfig is not defined");            
        }
        const _sprite_start_pos_numbers = this.jsonConfig['spriteOutPos'];
        if (!defined(_sprite_start_pos_numbers)) {
            throw new Error("this.jsonConfig['spriteOutPos'] is not defined"); 
        }
        if (_sprite_start_pos_numbers.length < 2) {
            throw new Error("this.jsonConfig['spriteOutPos'] is not error, need[path,pointindex]");
        }

        this.spriterStartPosition = this.indexCion(_sprite_start_pos_numbers[0], _sprite_start_pos_numbers[1]);
        if (!defined(this.spriterStartPosition)) {
            throw new Error("this.jsonConfig['spriteOutPos'] is not error, [path,pointindex] not for node post");
        }
    }

    private initAnimatioNode() {       
        this.animationNode = new Node("SenceAnimation");
        this.animationNode.parent = this.node;
        this.animationSprite = this.animationNode.addComponent(Sprite);
        this.animationNode.setPosition(0.0, 0.0, 0.0);
    }
    public getAnimationNode() : Node {
        return this.animationNode;
    }
    public getAnimationSprite() : Sprite {
        return this.animationSprite;
    }
    
    /* 根据配置加载精灵， 根据active 配置进行显示，用于设为当前活动的精灵 */
    initializeSprites() {
        if (!defined(this.jsonConfig)) {
            throw new Error("this.jsonConfig is not defined");
        }
        const jsonConfig = this.jsonConfig;
        let sprites_option = jsonConfig['sprites'];
        if (!defined(sprites_option)){
            return;
        }
        if(!Array.isArray(sprites_option)) {
            return;
        }

        for( let sprite_option of sprites_option) {
            if (!defined(sprite_option)) {
                continue;
            }
            this.loadSprite(sprite_option);
        }
    }
    loadSprite(sprite_option: Object) {
        if (!defined(sprite_option)) {
            throw new Error("this.jsonConfig is not defined");
        }
        /**
         *      "lose":9001011,
         *      "failure":9001012,
         *      "victory":9001013,
         *      "walkanim":"spritewalk",
         *      "takedanim":"spritewalk",
         *      "failureanim":"spritewalk",
         *      "victoryanim":"spritewalk"   
         */
        let options = {
            name: sprite_option['name']??'defaultSprite',
            image: sprite_option['image'],
            imageDown: sprite_option['imageDown'],
            imageUp: sprite_option['imageUp'],
            imageLeft: sprite_option['imageLeft'],
            imageRight: sprite_option['imageRight'],
            startPosition: sprite_option['startPosition'],
            width: sprite_option['width'],
            height: sprite_option['height'],
            network: this._network,
            fatherNode: this.node,
            speedTime: sprite_option['speed']?? 0.05,
            spriteLoseAudio:sprite_option['lose']?? 9001011,               //被抓的音频
            spriteFailureAudio:sprite_option['failure']?? 9001012,         //失败的音频
            spriteVictoryAudio:sprite_option['victory']?? 9001013,         //胜利的音频
            spriteWalkAnim:sprite_option['walkanim']?? 9001017,            //行走的动画
            spriteTakeDAnim:sprite_option['takedanim']?? 9001018,          //被抓的动画
            spriteFailureAnim:sprite_option['failureanim']?? 9001019,      //失败的动画
            spriteVictoryAnim:sprite_option['victoryanim']?? 9001020       //胜利的动画
        }
        
        let _cursorSprite = this.node.addComponent(SpritePlayer);
        if(!defined(_cursorSprite)) {
            return;
        }
        _cursorSprite.setSeceneController(this);
        _cursorSprite.initialize(options);
        _cursorSprite.loadResources();
        _cursorSprite.spriteShow();
        _cursorSprite.onEventForCatchCion = this.onEventForCionEated;
        
        const spriter_activity = sprite_option['activity'];
        if (defined(spriter_activity) && (spriter_activity == 1)){
            this.spritePlayer = _cursorSprite;
            /* 确定初始位置 */
            if (defined(this.spriterStartPosition) ){
                /* 默认移动指定位置 */
                this.spritePlayer.moveForNodePos(this.spriterStartPosition);
                /* 启动精灵 */        
                this.spritePlayer.spriterun();
            }
        } else if (defined(this._SPRITED_IDLE_BUFFER)){
            /* 加入到等待队列中 */
            _cursorSprite.spriteIdle();     // 空闲状态
            this._SPRITED_IDLE_BUFFER.push(_cursorSprite);            
        }
    }

    /**
     * 初始化传送门
     */
    private initializeStages() {
        if (!defined(this.jsonConfig)) {
            throw new Error("this.jsonConfig is not defined");
        }
        const jsonConfig = this.jsonConfig;
        let stages_option = jsonConfig['stages'];
        if (!defined(stages_option)){
            return;
        }
        if(!Array.isArray(stages_option)) {
            return;
        }

        for( let stage_option of stages_option) {
            if (!defined(stage_option)) {
                continue;
            }
            this.loadStageFromJsonOption(stage_option);
        }
    }
    /**
     * 根据json 的配置，初始化传送门
     * @param option 
     */
    private loadStageFromJsonOption(stage_option: object) {
        if (!defined(stage_option)) {
            throw new Error("this.jsonConfig is not defined");
        }
        /**
         * {
         *   "name":"gatewayE101H",
         *   "image":9001022,
         *   "path": 9,
         *   "index":-1,
         *   "team": 1
         * }
         */
        let options = {
            name: stage_option['name']??'defaultStage',
            image: stage_option['image']??9001022,
            path: stage_option['path']??9,
            index: stage_option['index']??0,
            team: stage_option['team']??1,
        }
        
        let _cursorStage = this.node.addComponent(StageController);
        if(!defined(_cursorStage)) {
            return;
        }
        _cursorStage.setSceneController(this);
        _cursorStage.initialize(options);
        _cursorStage.loadResources();

        this.initNodePosForStag(options.path, options.index);

        const current_teamid = options.team;
        if (!this.stage_team_map.has(current_teamid)) {
            this.stage_team_map.set(current_teamid, new Array<StageController>());
        }
        const team_stage_list = this.stage_team_map.get(current_teamid);
        if (defined(team_stage_list)) {
            team_stage_list.push(_cursorStage);
        }

    }

    private initNodePosForStag(path: number,
        sindex: number) {
        if (!defined( this.CION_LIST )) {
            return;
        }
        if (this.CION_LIST.length <= 0) {
            return;
        }
        const length = this._network.getPathSize(path);
        if (length <= 0) {
            return;
        }

        if ( sindex < 0 ) {
            sindex = length + sindex; 
        }
        for (let _cion of this.CION_LIST) {
            if (_cion.hasExistPoints(path, sindex)){
                _cion.setStageSign(true);
            }
        }
    }
    
    /**
     * 新位置可以登上电梯
     * @param cion
     * @returns 
     */
    public newNodePosForElevator(cion: Cion): boolean {
        if (!defined(cion)) {
            return false;
        }
        if (!cion.getElevatorSign()) {
            return false;
        }
        if (!cion.getStageSign()) {
            return false;
        }
        return true;
    }
    
    public judgeEnterStage(spritePlayer: SpritePlayer): StageController | undefined {
        if (!defined(spritePlayer)) {
            return undefined;       
        }
        const _node_pos = spritePlayer.getNodePosition();       // cion
        for(let key of this.stage_team_map.keys()) {
            const stage_list = this.stage_team_map.get(key);
            if (!defined(stage_list)) {
                continue;
            }
            for (let stage of stage_list) {
                if (!defined(stage)) {
                    continue;
                }
                if (stage.hasSamePosition(_node_pos)) {
                    return stage;
                }
            } 
        }
        return undefined;
    }
    /**
     * 根据TeamId 获取其他TeamId 门，用于进行跳跃
     */
    public getStageByTeamId(teamid: number): Array<StageController> | undefined {
        if(!defined(this.stage_team_map)) {
            return undefined;
        }
        if (!this.stage_team_map.has(teamid)) {
            return undefined;
        }
        return this.stage_team_map.get(teamid);
    }

    public transmitToStage(stage: StageController): StageController | undefined {
        if (!defined(stage)) {
            return undefined;
        }
        const stages = this.getStageByTeamId(stage.getTeam());
        if ( !defined(stages)) {
            return undefined;   
        }
        for (let _stage of stages) {
            if (!defined(_stage)) {
                continue;
            }
            if (_stage == stage) {
                continue;
            }
            return _stage;
        }
        return undefined;
    }

    /**
     * 初始化传送门
     */
    private initializeElevators() {
        if (!defined(this.jsonConfig)) {
            throw new Error("this.jsonConfig is not defined");
        }
        const jsonConfig = this.jsonConfig;
        let elevators_option = jsonConfig['elevators'];
        if (!defined(elevators_option)){
            return;
        }
        if(!Array.isArray(elevators_option)) {
            return;
        }

        for( let elevator_option of elevators_option) {
            if (!defined(elevator_option)) {
                continue;
            }
            this.loadElevatorFromJsonOption(elevator_option);
        }
    }

    /**
     * 根据json 的配置，初始化传送门
     * @param option 
     */
    private loadElevatorFromJsonOption(elevator_option: object) {
        if (!defined(elevator_option)) {
            throw new Error("this.jsonConfig is not defined");
        }
        /**
         *{
         *  "name": "elevatorE101H",
         *  "image":9001021,
         *  "path":  21,
         *  "speed": 0.05,
         *  "startindex": 0,
         *  "endindex": -1
         * }
         */
        let options = {
            name: elevator_option['name']??'defaultElevator',
            image: elevator_option['image']?? 9001021,
            path: elevator_option['path']?? 9,
            speed: elevator_option['speed']?? 0.05,
            startindex: elevator_option['startindex']??0,
            endindex: elevator_option['endindex']??-1,
            team: elevator_option['team']??1,
            waittings:elevator_option['waittings']??[],         // 用于判断是否启动电梯
            onboards:elevator_option['onboards']??[],           // 用于判断是否登陆电梯
        }
        
        let _cursorElevator = this.node.addComponent(ElevatorController);
        if(!defined(_cursorElevator)) {
            return;
        }
        _cursorElevator.setSceneController(this );
        _cursorElevator.initialize(options);
        _cursorElevator.loadResources();
        this.initNodePostForElevator(options.path, options.startindex, options.endindex);
        if (defined(this.elevators)){
            this.elevators.push(_cursorElevator);
        }
        /* 根据StartIndex, 将电梯移动到指定位置 */
    }

    private initNodePostForElevator(path: number,
                                 startIndex: number,
                                 endIndex: number) {
        if (!defined( this.CION_LIST )) {
            return;
        }
        if (this.CION_LIST.length <= 0) {
            return;
        }
        const length = this._network.getPathSize(path);
        if (length <= 0) {
            return;
        }

        if ( endIndex < 0 ) {
            endIndex = length + endIndex; 
        }
        for (let _cion of this.CION_LIST) {
            for( let i = Math.min(startIndex, endIndex); i <= Math.max(startIndex, endIndex); i++) {
                if ( _cion.hasExistPoints( path, i ) ){
                    _cion.setElevatorSign(true);
                    _cion.activity = false;
                    _cion.show = false;
                    _cion.forEated = false;
                }
            }
        }
    }

    private cion_fen = 1;

    public addCatchFens() {
        this.cion_fen++;
    }

    public getCionFen() {
        return this.cion_fen;
    }

    /**
     * 金币被吃掉。
     * 该事件，由精灵响应，用于
     * 记录得分
     */
    public onEventForCionEated(spritePlay: SpritePlayer) {
        if (!defined(spritePlay)){
            return;
        }
        if (!defined(spritePlay.getNodePosition())){
            return;
        }
        const _secenController = spritePlay.getSeceneController();
        if (!defined(_secenController)){
            return;
        }
        if(spritePlay.getNodePosition().activity){        
            _secenController.addCatchFens();
            _secenController.showLabel(_secenController.getCionFen().toString());
        } 
        /* 是否胜利， 则播放 */
        if(_secenController.judgeVictoryConfirm()) {
            /* 播放胜利的声音 */
            _secenController.audioPlayStop();
            /* 播放成果 */
            _secenController.playVictoryAudio();
            /* 播放动画 */
            _secenController.playAnimationForSpriteVK();
        }
    } 
    /**
     * 精灵被抓事件， 
     * 用于更新数量
     * 该事件，有Hunter 响应
     * @param spritePlay 
     * @param hunterPosition 
     */
    public onEventForHunterCatchSprite() {
        if (!defined(this.spritePlayer)){
            return;
        }
        /* 播放特殊lost audio */
        this.audioPlayStop();
        this.playLoseAudio();
        /* Hide */
        this.spritePlayer.spritestop();
        this.spritePlayer.spriteNoLife();
        this.spritePlayer.spriteNoShow();
        if (defined(this._SPRITED_TAKEED_BUFFER)) {
            this._SPRITED_TAKEED_BUFFER.push(this.spritePlayer);
        }
        /* 隐藏 */        
        this.spritePlayer = null;

        if (this._SPRITED_IDLE_BUFFER.length < 1) {
            this.spritePlayGameFailure();
            return; 
        }
        /* 播放被抓动画 */
        const timer = setTimeout(()=>{
            this.playAnimationForSpriteTaked(this.playAnimationFinished);
            clearTimeout(timer);                        
        }, 200);
        
    }
    
    public startNextSpriteOnLine() {
        if (this._SPRITED_IDLE_BUFFER.length < 1) {
            this.spritePlayGameFailure();
            return; 
        }
        this.spritePlayer = this._SPRITED_IDLE_BUFFER.pop();
        /* 移动精灵到初始位置 */
        if(!defined(this.spritePlayer)){
            this.spritePlayGameFailure();
            return;
        }
        if(!defined(this.spriterStartPosition)){
            return;
        }
        this.spritePlayer.onEventForCatchCion = this.onEventForCionEated;
        //this.spritePlayer.onEventForMovePos
        /* 移动到初始位置 */
        this.spritePlayer.moveForNodePos(this.spriterStartPosition);
        /* 启动精灵 */        
        this.spritePlayer.spriterun();
    }

    /**
     * 精灵游戏结束，进入重新开始
     */
    public spritePlayGameFailure() {
        const timer = setTimeout(()=>{
            this.playFailureAudio();
            this.playAnimationForSpriteFailure(this.playAnimationFinished);
            clearTimeout(timer);                        
        }, 200);
        
    }

    /**
     * 判断vectory
     */
    public judgeVictoryConfirm() : boolean {
        for( let cion of this.CION_LIST ) {
            if (!defined(cion)) {
                continue;
            }
            if ( (cion.activity) &&
                 (!cion.isCionEated()) ) {
                return false;
            } 
        }
        return true;
    }

    hasSpritePlayer(): boolean {
        return defined(this.spritePlayer);
    }

    initializeHunter() {
        if (!defined(this.jsonConfig)) {
            throw new Error("SecenseTools.jsonConfig is not defined");
        }
        const jsonConfig = this.jsonConfig;
       
        let hunter_options = jsonConfig['belials'];
        if (!defined(hunter_options)) {
            throw new Error("SecenseTools.jsonConfig belials is not defined");
        }

        if (hunter_options.length <= 0) {
            throw new Error("SecenseTools.jsonConfig belials is not defined");
        }

        for( let hunter_option of hunter_options ){
            if(!defined(hunter_option)){
                continue;
            }
            let options = {
                name: hunter_option['name']??'defaultHunter',
                image: hunter_option['image'],
                startPosition: hunter_option['startPosition'],
                width: hunter_option['width'],
                height: hunter_option['height'],
                network: this._network,
                fatherNode: this.node,
                speed:hunter_option['speed'],
                flesh:hunter_option['flesh'],
                path:hunter_option['path'],
                model:hunter_option['model'],
                TSPlayer: this.spritePlayer               
            }
            let hunter = this.node.addComponent(BelialHunter);
            if(!defined(hunter)) {
                continue;
            }
            hunter.setSeceneController( this );
            hunter.initialize(options);           
            hunter.loadResources();

            if (!defined(this.BELIALS_BUFFER)) {
                this.BELIALS_BUFFER = [];
            }
            this.BELIALS_BUFFER.push(hunter);
        }        
    }

    public backAutoSource : AudioSource = null;
    /**
     * 初始化音频
     */
    initAudio() {
        if (!defined(this.jsonConfig)) {
            throw new Error("SecenseTools.jsonConfig is not defined");
        }
        this._bk_audio_rid = this.jsonConfig['bkgdaudio']??9001010;
        this._sprite_lose_audio = this.jsonConfig['lose']??9001011;                 //"lose":9001011,
        this._sprite_failure_audio = this.jsonConfig['failure']??9001012;           // "failure":9001012,
        this._sprite_victory_audio = this.jsonConfig['victory']??9001013;           // "victory":9001013,

        this.backAutoSource = this.node.getComponent(AudioSource);       
        if (!defined(this.backAutoSource)) {
            this.backAutoSource = this.node.addComponent(AudioSource); 
        }  
        
        this.bkAudioPlay();
    }
    /**
     * 初始化动画
     */
    initAnimation() {
        this._sprite_walkanim_anima = this.jsonConfig['walkanim']??80110001;        // "walkanim":80110001,
        this._sprite_takedanim_anima = this.jsonConfig['takedanim']??80110004;      // "takedanim":80110004,
        this._sprite_failureanim_anima = this.jsonConfig['failureanim']??80110002;  // "failureanim":80110002,
        this._sprite_victoryanim_anima = this.jsonConfig['victoryanim']??80110003;  // "victoryanim":80110003,
    }
    
    bkAudioPlay() {
        if (!defined(this.backAutoSource)) {
            throw new Error("SecenseTools.backAutoSource is not defined");
        }
        const audio_resources = SecenesManager.getInstance().getResource(this._bk_audio_rid) as HAudioResource;
        if (!defined(audio_resources)) {
            throw new Error("SecenseTools.jsonConfig's bkgdaudio is not defined");
        }
        this.backAutoSource.clip = audio_resources.audioClip;
        this.backAutoSource.loop = true;
        this.backAutoSource.play();
    }

    audioPlayPause() {
        if (!defined(this.backAutoSource)) {
            throw new Error("SecenseTools.backAutoSource is not defined");
        }      
        this.backAutoSource.pause();
    }

    audioPlayStop() {
        if (!defined(this.backAutoSource)) {
            throw new Error("SecenseTools.backAutoSource is not defined");
        }
        this.backAutoSource.stop();
    }

    public playLoseAudio() {
        
        if (!defined(this.backAutoSource)) {
            throw new Error("SecenseTools.backAutoSource is not defined");
        }
        const audio_resources = SecenesManager.getInstance().getResource(this._sprite_lose_audio) as HAudioResource;
        if (!defined(audio_resources)) {
            throw new Error("SecenseTools.jsonConfig's _sprite_lose_audio is not defined");
        }
        this.backAutoSource.clip = audio_resources.audioClip;
        this.backAutoSource.loop = false;
        this.backAutoSource.playOneShot(audio_resources.audioClip);        
    }

    public playFailureAudio() {
        if (!defined(this.backAutoSource)) {
            throw new Error("SecenseTools.backAutoSource is not defined");
        }
        const audio_resources = SecenesManager.getInstance().getResource(this._sprite_failure_audio) as HAudioResource;
        if (!defined(audio_resources)) {
            throw new Error("SecenseTools.jsonConfig's _sprite_failure_audio is not defined");
        }
        this.backAutoSource.clip = audio_resources.audioClip;
        this.backAutoSource.loop = false;
        this.backAutoSource.playOneShot(audio_resources.audioClip); 
    }

    public playVictoryAudio() {
        if (!defined(this.backAutoSource)) {
            throw new Error("SecenseTools.backAutoSource is not defined");
        }
        const audio_resources = SecenesManager.getInstance().getResource(this._sprite_victory_audio) as HAudioResource;
        if (!defined(audio_resources)) {
            throw new Error("SecenseTools.jsonConfig's _sprite_victory_audio is not defined");
        }
        this.backAutoSource.clip = audio_resources.audioClip;
        this.backAutoSource.loop = false;
        this.backAutoSource.playOneShot(audio_resources.audioClip); 
    }

    
    /**
     * 根据rid 加载金币效果
     * @param rid 
     */
    loadIcons(rid: number, stage_sv: number[], elevator_sv:number[]) {
        let lines_indices = this._network.linesIndices;
        Check.defined("indices", lines_indices.indices);
        let _cursor_index = 0;
        let i = 0;
        while( _cursor_index < lines_indices.indices.length ) {
            let _layer = lines_indices.indices[_cursor_index];
            let _p_index = lines_indices.indices[_cursor_index + 1];
            const point_pos = this._network.indexPoints(_layer, _p_index);
            if (!defined(point_pos)){
                _cursor_index += 2;
                continue;
            }
            let _has_exists = false;
            for (let _cion of this.CION_LIST) {
                if (_cion.hasSamePosition(_layer, _p_index, true)) {
                    _has_exists = true;
                    if ((!defined(stage_sv)) && (!defined(elevator_sv))){
                        _cion.showME();    
                    } else if((stage_sv.indexOf(_layer) == -1) && 
                              (elevator_sv.indexOf(_layer) == -1)) {
                        _cion.showME(); 
                    } 
                    break;
                } 
            }
            if (!_has_exists) {
                
                let _cion = this.node.addComponent(Cion);
                _cion.initME("cion_" + i, 
                            point_pos,
                            this._network,
                            rid, false);                 
                
                this.CION_LIST.push(_cion);    
                _cion.points.push(_layer)
                _cion.points.push(_p_index)    
                i++;
            }
            _cursor_index += 2;
        }             
    }

    /**
     * 加载节点，并设置为金币 
     */
    loadIconsComponent() {
        if (!defined(this.jsonConfig)) {
            throw new Error("SecenseTools.jsonConfig is not defined");
        }
        const jsonConfig = this.jsonConfig;
        const items = jsonConfig["netpolyline"];
        if (!defined(items)) {
            throw new Error("SecenseTools.jsonConfig's netpolyline is not defined");
        }
        const paths = items["paths"];
        if (!defined(paths)) {
            throw new Error("SecenseTools.jsonConfig's netpolyline's paths is not defined");
        }
        /* 读取偏移，将物理坐标系，转换成平面坐标系 */
        const rotation = items["rotation"];
        if (!defined(rotation)) {
            throw new Error("SecenseTools.jsonConfig's netpolyline's rotation is not defined");
        }
        /* 偏移矩阵 */
        const c_rotation = new Cartesian3(rotation[0], rotation[1], rotation[2]);

        /* 读取比例尺 */
        const scale = items["scale"];
        if (!defined(scale)) {
            throw new Error("SecenseTools.jsonConfig's netpolyline's scale is not defined");
        }
        /* 旋转矩阵 */
        const c_scale = new Cartesian3(scale[0], scale[1], scale[2]);

        const _distance = items["distance"];
        if (!defined(scale)) {
            throw new Error("SecenseTools.jsonConfig's netpolyline's distance is not defined");
        }

        let path_index_for_stage : Array<number> = [];
        let path_index_for_elevator : Array<number> = [];

        this._network = new HNetsPolyline();
        for (let path of paths) {
            if (!defined(path)) {
                continue;
            }
            const layer_id = path["layer"]; 
            if (!defined(layer_id)) {
                continue;
            }
            const _points = path["path"]; 
            if (!defined(_points)) {
                continue;
            }
            this._network.pushBackPS(layer_id, _points);
            
            const stage_sign = path["forstage"];
            if(defined(stage_sign) &&
                (stage_sign)) {
                path_index_for_stage.push(layer_id);
            }

            const elevator_sign = path["elevatorpath"];
            if(defined(elevator_sign) &&
                (elevator_sign)) {
                path_index_for_elevator.push(layer_id);
            }
        }

        /* 根据长度进行切分 */
        this._network.interpolationDistanceForStraightLine(_distance);
        /* 移动坐标 */
        this._network.add(c_rotation);
        /* 比例放大 */
        this._network.multiplyComponents(c_scale);
        /* 增加node, Strip 模式*/
        Check.defined("linesIndices",  this._network.linesIndices);
        Check.defined("CION_LIST",  this.CION_LIST);
        let i = 0;
        const cion_rid = jsonConfig['cion'];
        if (defined(cion_rid)) {
            /* 创建cion 并显示 */
            this.loadIcons(cion_rid, path_index_for_stage, path_index_for_elevator);
        }
        /* 默认等待5秒 */
        SecenseTools.MAX_IDLE_TIME_CION = jsonConfig['ciontime']??5;

    }  // loadIconsComponent

    playAnimationForSpriteTaked(_play_finish_call:(_secenceTools: SecenseTools)=>void) {  
        const _seceneTools = this;
        const _sprite_node = this.node.getChildByName("animspritetaked");
        if (!defined(_sprite_node)) {
            return;
        }
        const sprite = _sprite_node.getComponent(Sprite);
        if (!defined(sprite)) {
            return;
        }
        
        sprite.enabled = true;
        if (defined(this.spriterStartPosition)) {
            _sprite_node.setPosition(
                    this.spriterStartPosition.position.x,
                    this.spriterStartPosition.position.y,
                    this.spriterStartPosition.position.z);
        }

        let _sprite_anim = _sprite_node.getComponent(Animation);
        if (!defined(_sprite_anim)) {
            _sprite_anim = _sprite_node.addComponent(Animation);
        } 

        let _father_secene = this;
        _sprite_anim.on(Animation.EventType.FINISHED, ()=>{
            _sprite_anim.destroy();
            _seceneTools.startNextSpriteOnLine();
            /* 重新播放北京音乐 */
            if(defined(_play_finish_call)) {
                _play_finish_call(_father_secene);
            }
            sprite.enabled = false;            
        });

        const anim_clip_result = SecenesManager.getInstance().getResource(this._sprite_takedanim_anima) as HAnimationResource;
        if (!defined(anim_clip_result)) {            
            _seceneTools.startNextSpriteOnLine();
            sprite.enabled = false;
            return;
        }

        const clip = anim_clip_result.animationClip;
        if (!defined(clip)) {
            _seceneTools.startNextSpriteOnLine();
            sprite.enabled = false;
            return;
        } 
        clip.wrapMode = AnimationClip.WrapMode.Loop; 
        _sprite_anim.addClip(clip);
        _sprite_anim.defaultClip = clip;

        let _animation_state = _sprite_anim.getState(clip.name);
        if (defined(_animation_state ) ){
            _animation_state.repeatCount = 2;
            _animation_state.speed = 1.0;
        }
        SecenseTools.PLAY_ANIM_SIGN = true;
        _sprite_anim.play();        
    }

    playAnimationFinished(_secenceTools: SecenseTools) {
        SecenseTools.PLAY_ANIM_SIGN = false;
        if (defined(_secenceTools)) {
            _secenceTools.bkAudioPlay();
        }
    }

    _refresh_cion_time : number = 0;

    update(deltaTime: number) {
        this.judgeHunterCatchSprite();
        this._refresh_cion_time += deltaTime;
        if (this._refresh_cion_time >= 0.5) {            
            this.updateTimeStampForCion(this._refresh_cion_time);
            this.relifeForTimeoutCion();
            this._refresh_cion_time = 0;
        }
    }
    
    playAnimationForSpriteFailure(_play_finish_call:(_secenceTools: SecenseTools)=>void) {       
        
        const _seceneTools = this;
        const _sprite_node = this.node.getChildByName("animspriteFailure");
        if (!defined(_sprite_node)) { 
            return;
        }
        _sprite_node.setPosition(0.0, 0.0, 0.0);
        let _sprite_anim = _sprite_node.getComponent(Animation);
        if (!defined(_sprite_anim)) {
            _sprite_anim = _sprite_node.addComponent(Animation);
        }
        const sprite = _sprite_node.getComponent(Sprite);
        if (!defined(sprite)) { 
            return;
        }

        let _father_secene = this;
        
        sprite.enabled = true;
        _sprite_anim.on(Animation.EventType.FINISHED, ()=>{
            sprite.enabled = false; 
            _sprite_anim.destroy();
            if(defined(_play_finish_call)) {
                _play_finish_call(_father_secene);
            }

        });
        const anim_clip_result = SecenesManager.getInstance().getResource(this._sprite_failureanim_anima) as HAnimationResource;
        if (!defined(anim_clip_result)) {
            sprite.enabled = false;
            return;
        }
        const clip = anim_clip_result.animationClip;
        if (!defined(clip)) {
            sprite.enabled = false;
            return;
        } 
        clip.wrapMode = AnimationClip.WrapMode.Loop; 
        _sprite_anim.addClip(anim_clip_result.animationClip);
        _sprite_anim.defaultClip = anim_clip_result.animationClip;
        let _animation_state = _sprite_anim.getState(clip.name);
        if (defined(_animation_state ) ){
            _animation_state.repeatCount = 10;
            _animation_state.speed = 1.0;
        }
        SecenseTools.PLAY_ANIM_SIGN = true;
        _sprite_anim.play();

    }

    playAnimationForSpriteVK() {               
        const _seceneTools = this;
        const _sprite_node = this.node.getChildByName("animspriteVK");
        if (!defined(_sprite_node)) { 
            return;
        }
        _sprite_node.setPosition(0.0, 0.0, 0.0);
        let _sprite_anim = _sprite_node.getComponent(Animation);
        if (!defined(_sprite_anim)) {
            _sprite_anim = _sprite_node.addComponent(Animation);
        }
        const sprite = _sprite_node.getComponent(Sprite);
        if (!defined(sprite)) { 
            return;
        }
        
        sprite.enabled = true;
        _sprite_anim.on(Animation.EventType.FINISHED, ()=>{
            _sprite_anim.destroy();
            sprite.enabled = false;            
        });

        const anim_clip_result = SecenesManager.getInstance().getResource(this._sprite_victoryanim_anima) as HAnimationResource;
        if (!defined(anim_clip_result)) {
            sprite.enabled = false;
            return;
        }
        const clip = anim_clip_result.animationClip;
        if (!defined(clip)) {
            sprite.enabled = false;
            return;
        } 
        clip.wrapMode = AnimationClip.WrapMode.Loop; 
        _sprite_anim.addClip(anim_clip_result.animationClip);
        _sprite_anim.defaultClip = anim_clip_result.animationClip;
        let _animation_state = _sprite_anim.getState(clip.name);
        if (defined(_animation_state ) ){
            _animation_state.repeatCount = 10;
            _animation_state.speed = 1.0;
        }
        _sprite_anim.play();

    }

    public getSpritePlayNodePos() : Cion | null {
        if (!defined(this.spritePlayer)) {
            return null;
        }
        return this.spritePlayer.getNodePosition();
    }
    public static LOCL_SIGN = false;
    public static PLAY_ANIM_SIGN = false;

    public _time_stamp = 0;
    public judgeHunterCatchSprite() : boolean {
        if (SecenseTools.PLAY_ANIM_SIGN){
            return false;
        }
        if ( !defined(this.spritePlayer)) {
            return false;
        }
        if (!defined(this.BELIALS_BUFFER)) {
            return;
        }
        if (this.BELIALS_BUFFER.length <= 0) {
            return;
        }
        // if (this.spritePlayer.isStop()) {
        //     return;
        // }
        let sprite_catched = false;
        try {
            if(!SecenseTools.LOCL_SIGN) {
                SecenseTools.LOCL_SIGN = true;
                const _node_pos_sprite = this.spritePlayer.getNodePosition();
                if (!defined(_node_pos_sprite)) {
                    return false; 
                }
                /* 遍历所有的精灵，判断是否被捕获 */
                for (let baliav of this.BELIALS_BUFFER) {
                    if (!defined(baliav)) {
                        continue;
                    }
                    let nodes_pos = baliav.getNodePosition();
                    if (!defined(nodes_pos) ) {
                        continue;
                    }
                    if (nodes_pos.equalsPosition(_node_pos_sprite)) {
                        sprite_catched = true;
                        break;
                    }
                }
                if(sprite_catched){                    
                    SecenseTools.PLAY_ANIM_SIGN = true;                    
                    this.onEventForHunterCatchSprite();
                }
            }
            SecenseTools.LOCL_SIGN = false;
        }catch(err){
            console.error(err);
        }finally{
            SecenseTools.LOCL_SIGN = false;
        }

        return sprite_catched;
    }

    public updateTimeStampForCion(_time_stamp: number) {
        if(!defined(this.CION_LIST)) {
            return;
        }
        for(let _cursor_cion of this.CION_LIST) {
            if (!defined(_cursor_cion)) {
                continue;
            }
            _cursor_cion.updateTimeStamp(_time_stamp);
        }
    }
    public relifeForTimeoutCion() {
        if(!defined(this.CION_LIST)) {
            return;
        }
        for(let _cursor_cion of this.CION_LIST) {
            if (!defined(_cursor_cion)) {
                continue;
            }
            if (_cursor_cion.isCanRelife()) {
                _cursor_cion.relife();
            }
        }
    }
}
let _catch_count = 0;
export type LoadCallBack = (input: SecenseTools)=>void;


